package com.design_mode;

/**
 * Created by dustaple on 8/1/14.
 */
public class CommandPattern {
    public static void miain(String[] args) {
        Invoke invoke = new Invoke();
        Receiver soldier = new Soldier();
        Command command = new FightCommand((Soldier) soldier);
        invoke.setCommand(command);
        invoke.action();
    }
}

interface Command {
    void excuteCommand();
}

interface Receiver {
    void doExcute();
}

class Soldier implements Receiver {
    @Override
    public void doExcute() {
        System.out.println("Shot at the enemy!");
    }
}

class FightCommand implements Command {

    Soldier soldier;

    public FightCommand(Soldier receiver) {
        soldier = receiver;
    }

    @Override
    public void excuteCommand() {
        System.out.println("Start to fight against the enemy!");
        soldier.doExcute();
    }
}

class Invoke {
    private Command command;

    public void setCommand(Command command) {
        this.command = command;
    }

    public void action() {
        command.excuteCommand();
    }
}